package com.ifp.opengate.boot.validator.service;

import com.ifp.opengate.boot.bean.ValidateEntity;
import com.ifp.opengate.boot.bean.ValidatorForm;
import com.ifp.opengate.boot.exception.AccessControlException;
import com.ifp.opengate.boot.validator.ValidateService;

/**
 * <p>
 * 参数验证抽象类
 * </P>
 *
 * @author zhuzh@belink.com
 * @version 0.0.1
 * @className ValidateServiceImpl
 * @sine 2020/3/26 14:10
 */
public abstract class ValidateServiceImpl implements ValidateService {

    /**
     * 检验数据，不通过 时抛出异常
     *
     */
    public void validate(Object obj, ValidatorForm validatorForm)
        throws IllegalArgumentException, IllegalAccessException, AccessControlException {
        ValidateEntity entity = validateValue(validatorForm, obj);
        if (entity != null) {
            throw new AccessControlException(entity.getErrorCode(), entity.getErrorMsg());
        }
    }

    /**
     * @Description:
     *
     * @param validatorForm validatorForm
     * @param data data
     * @return com.gift.domain.infrastructure.ability.dto.data.ValidateEntity
     */
    public abstract ValidateEntity validateValue(ValidatorForm validatorForm, Object data);
}
